package com.playball.lottery.customview;

import com.playball.lottery.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.InputType;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class DltxhDialog extends Dialog {

    Button buy_dltxh_dialog_reddel_Button;
    Button buy_dltxh_dialog_redadd_Button;
    EditText buy_dltxh_dialog_red_EditText;

    Button buy_dltxh_dialog_bluedel_Button;
    Button buy_dltxh_dialog_blueadd_Button;
    EditText buy_dltxh_dialog_blue_EditText;

    Context context;
    View view;
    private int i = 5;
    private int y = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(view);
	ViewInit();

	buy_dltxh_dialog_reddel_Button.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		// TODO Auto-generated method stub
		i = Integer.parseInt(buy_dltxh_dialog_red_EditText.getText().toString());
		if (i < 6) {
		    i = 5;
		} else {
		    i--;
		    buy_dltxh_dialog_red_EditText.setText(i + "");
		}

	    }
	});

	buy_dltxh_dialog_redadd_Button.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		// TODO Auto-generated method stub
		i = Integer.parseInt(buy_dltxh_dialog_red_EditText.getText().toString());
		i++;
		if (i > 18) {
		    buy_dltxh_dialog_red_EditText.setText("18");
		    i = 18;
		} else {
		    buy_dltxh_dialog_red_EditText.setText(i + "");
		}
	    }
	});

	buy_dltxh_dialog_bluedel_Button.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		// TODO Auto-generated method stub
		y = Integer.parseInt(buy_dltxh_dialog_blue_EditText.getText().toString());
		if (y < 3) {
		    y = 2;
		} else {
		    y--;
		    buy_dltxh_dialog_blue_EditText.setText(y + "");
		}

	    }
	});

	buy_dltxh_dialog_blueadd_Button.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		// TODO Auto-generated method stub
		y = Integer.parseInt(buy_dltxh_dialog_blue_EditText.getText().toString());
		y++;
		if (y > 12) {
		    buy_dltxh_dialog_blue_EditText.setText("12");
		    y = 12;
		} else {
		    buy_dltxh_dialog_blue_EditText.setText(y + "");
		}
	    }
	});

    }

    public void ViewInit() {

	buy_dltxh_dialog_reddel_Button = (Button) findViewById(R.id.buy_dltxh_dialog_reddel_Button);
	buy_dltxh_dialog_redadd_Button = (Button) findViewById(R.id.buy_dltxh_dialog_redadd_Button);
	buy_dltxh_dialog_red_EditText = (EditText) findViewById(R.id.buy_dltxh_dialog_red_EditText);
	buy_dltxh_dialog_red_EditText.setOnTouchListener(new View.OnTouchListener() {
	    public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		int inType = buy_dltxh_dialog_red_EditText.getInputType();
		buy_dltxh_dialog_red_EditText.setInputType(InputType.TYPE_NULL);
		buy_dltxh_dialog_red_EditText.onTouchEvent(event);
		buy_dltxh_dialog_red_EditText.setInputType(inType);

		return true;
	    }
	});

	buy_dltxh_dialog_bluedel_Button = (Button) findViewById(R.id.buy_dltxh_dialog_bluedel_Button);
	buy_dltxh_dialog_blueadd_Button = (Button) findViewById(R.id.buy_dltxh_dialog_blueadd_Button);
	buy_dltxh_dialog_blue_EditText = (EditText) findViewById(R.id.buy_dltxh_dialog_blue_EditText);
	buy_dltxh_dialog_blue_EditText.setOnTouchListener(new View.OnTouchListener() {
	    public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		int inType = buy_dltxh_dialog_blue_EditText.getInputType();
		buy_dltxh_dialog_blue_EditText.setInputType(InputType.TYPE_NULL);
		buy_dltxh_dialog_blue_EditText.onTouchEvent(event);
		buy_dltxh_dialog_blue_EditText.setInputType(inType);

		return true;
	    }
	});

    }

    // 不加样式
    public DltxhDialog(Context context) {
	super(context);
	// TODO Auto-generated constructor stub
	this.context = context;
    }

    // 加样式
    public DltxhDialog(Context context, int theme) {
	super(context, theme);
	this.context = context;
    }

    // 指定View 、加样式
    public DltxhDialog(Context context, View view, int theme) {
	super(context, theme);
	this.context = context;
	this.view = view;
    }
}
// 有问题，还不能用，日后解决
// 此处直接new一个Dialog对象出来，在实例化的时候传入主题
// Dialog dialog = new Dialog(SsqxhActivity.this,
// R.style.ActivityDialogTheme);
// 设置它的ContentView,并显示
// dialog.setContentView(R.layout.buy_dltxh_dialog);
// dialog.show();

// // 从资源创建视图
// LayoutInflater inflater = LayoutInflater.from(SsqxhActivity.this);
// final View view = inflater.inflate(R.layout.buy_dltxh_dialog, null);
// // 创建对话框
// AlertDialog.Builder dialog = new AlertDialog.Builder(SsqxhActivity.this);
// dialog.setView(view);
// dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// // TODO Auto-generated method stub
//
// }
// });
// dialog.setPositiveButton("取消", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// // TODO Auto-generated method stub
// dialog.cancel();
// }
// });